package demo.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author created by wangyang
 * email:techyang.wangy@ymm56.com
 * company: yunmanman
 * @date 2018/9/10 下午7:10
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("before:" + beanName);
        if (bean instanceof HelloComponentLifeCycle) {
            System.out.println(((HelloComponentLifeCycle) bean).getHello());
        }
        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("after:" + beanName);
        if (bean instanceof HelloComponentLifeCycle) {
            System.out.println(((HelloComponentLifeCycle) bean).getHello());
        }
        return null;
    }
}
